package avicit.bdp.dds.api.controller;

import avicit.bdp.dds.api.dto.lineage.LineageDto;
import avicit.bdp.dds.api.dto.lineage.NodeDto;
import avicit.bdp.dds.api.service.LineageRelationService;
import avicit.bdp.dds.dao.entity.ProcessDefinition;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2024-07-15 14:31
 * @类说明：血缘关系REST接口
 * @修改记录：
 */
@RestController
@Api(tags = "血缘关系REST接口")
@RequestMapping("/api/bdp/dds/lineage")
public class LineageRelationRest {

    @Autowired
    private LineageRelationService lineageRelationService;

    /**
     * 查询表相关血缘
     */
    @ApiOperation(value = "查询表相关血缘")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableId", value = "表id", dataType = "String")
    })
    @GetMapping(value = "/getTableLineageRelation")
    public ResponseMsg<LineageDto> getTableLineageRelation(@RequestParam(value = "tableId") String tableId) {
        ResponseMsg<LineageDto> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(lineageRelationService.getTableLineageRelation(tableId));
        return responseMsg;
    }

    /**
     * 根据字段血缘反查任务信息
     */
    @ApiOperation(value = "根据字段血缘反查任务信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineageFieldId", value = "血缘字段id", dataType = "String")
    })
    @GetMapping(value = "/getProcessDefinitionList")
    public ResponseMsg<List<ProcessDefinition>> getProcessDefinitionList(@RequestParam(value = "lineageFieldId") String lineageFieldId) {
        ResponseMsg<List<ProcessDefinition>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(lineageRelationService.getProcessDefinitionList(lineageFieldId));
        return responseMsg;
    }

    /**
     * 查询任务SQL
     */
    @ApiOperation(value = "查询任务SQL")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "processDefinitionId", value = "流程定义id", dataType = "String")
    })
    @GetMapping(value = "/getProcessDefinitionSQL")
    public ResponseMsg<List<NodeDto>> getProcessDefinitionSQL(@RequestParam(value = "processDefinitionId") String processDefinitionId) {
        ResponseMsg<List<NodeDto>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(lineageRelationService.getProcessDefinitionSQL(processDefinitionId));
        return responseMsg;
    }

}
